package errorcode

import "encoding/json"

type ErrorCode struct {
	Code     string
	Details  string
	location string
}

func (er *ErrorCode) SetLocation(location string) {
	er.location = location
}

func NewErr(errCode string, fmt string, args ...any) *ErrorCode {
	return NewErrWithCause(errCode, nil, fmt, args...)
}

func NewErrWithCause(errCode string, cause *ErrorCode, fmt string, args ...any) *ErrorCode {
	return &ErrorCode{
		Code:    errCode,
		Details: fmt,
	}
}

func (er *ErrorCode) String() string {
	data, _ := json.Marshal(er)
	return string(data)
}
